package com.ruoyi.car.controller.parts;

import com.car.pojo.Result;
import com.car.pojo.TbPartTerminalInformation;
import com.ruoyi.car.service.parts.ITbPartTerminalInformationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车载终端信息控制类
 */
@Controller
@RequestMapping("/terminalInformation")
public class TbPartTerminalinformationController extends BaseController {
    @Autowired
    private ITbPartTerminalInformationService terminalInformationService;

    private String prefix = "system/carparts/information";

    @RequiresPermissions("carparts:information:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/information";
    }
    /**
     * 模糊查询：终端型号名称、终端型号编号、终端种类
     * @return
     */
    @PostMapping("/terminalInformationList")
    @ResponseBody
    public TableDataInfo terminalInformationList(TbPartTerminalInformation tbPartTerminalInformation){
        startPage();
        List<TbPartTerminalInformation> tbPartTerminalInformations = this.terminalInformationService.terminalTypeList(tbPartTerminalInformation.getTerminalName(), tbPartTerminalInformation.getTerminalId(), tbPartTerminalInformation.getTerminalModelId());
        System.out.println(tbPartTerminalInformations);
        return getDataTable(tbPartTerminalInformations);
    }

    /**
     * 跳转添加车载终端页面
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增代码
     * @param tbPartTerminalInformation
     * @return
     */
    @PostMapping("/terminalInformationInsert")
    @ResponseBody
    public void terminalInformationInsert(TbPartTerminalInformation tbPartTerminalInformation){
            this.terminalInformationService.terminalInformationInsert(tbPartTerminalInformation);
    }
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap map){
        //回显数据
        TbPartTerminalInformation tbPartTerminalInformation = this.terminalInformationService.terminalInformationById(id);
        map.put("tbPartTerminalInformation",tbPartTerminalInformation);
        return prefix + "/edit";
    }

    /**
     * 修改当前数据
     * @param tbPartTerminalInformation
     * @return
     */
    @PostMapping("/terminalInformationUpdate")
    @ResponseBody
    public void terminalInformationUpdate(TbPartTerminalInformation tbPartTerminalInformation){
            this.terminalInformationService.terminalInformationUpdate(tbPartTerminalInformation);
    }
    @GetMapping("/terminalInformationById/{id}")
    @ResponseBody
    public TbPartTerminalInformation temrinalInformationById(@PathVariable("id")Long id){
        TbPartTerminalInformation tbPartTerminalInformation = this.terminalInformationService.terminalInformationById(id);
        return tbPartTerminalInformation;
    }
}
